﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;
using System.Diagnostics;
using System.Windows.Threading;


namespace ZhwangTool
{

    public class MainViewModel
    {
        //private PerformanceCounter cpuCounter;

        public MainViewModel()
        {
            //cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");

            this.DynamicCurve = new PlotModel { Title = "" };

            //定义x轴
            OxyPlot.Axes.LinearAxis bottomAxis = new OxyPlot.Axes.LinearAxis()
            {
                Position = AxisPosition.Bottom,
                //IsAxisVisible = false,//X轴不显示
                Title = "桩号",//显示标题内容
                TitlePosition = 1,//显示标题位置
                //TitleColor = OxyColor.Parse("#d3d3d3"),//显示标题位置
                IsZoomEnabled = true,//坐标轴缩放关闭
                IsPanEnabled = true,//图表缩放功能关闭
                MajorGridlineStyle = LineStyle.Solid,
                MinorGridlineStyle = LineStyle.Dot,
                CropGridlines = true
            };
            //定义y轴
            OxyPlot.Axes.LinearAxis leftAxis = new OxyPlot.Axes.LinearAxis()
            {
                Position = AxisPosition.Left,
                Minimum = 0,
                Maximum = 100,
                Title = "高程",//显示标题内容
                TitlePosition = 1,//显示标题位置
                //TitleColor = OxyColor.Parse("#d3d3d3"),//显示标题位置
                IsZoomEnabled = true,//坐标轴缩放关闭
                IsPanEnabled = true,//图表缩放功能关闭
                MajorGridlineStyle = LineStyle.Solid,
                MinorGridlineStyle = LineStyle.Dot,
                CropGridlines=true
            };

            DynamicCurve.Axes.Add(bottomAxis);
            DynamicCurve.Axes.Add(leftAxis);
            sjxSseries = new LineSeries()
            {
                Color = OxyColors.Red,
                StrokeThickness = 2,
                MarkerSize = 1.5,
                MarkerStroke = OxyColors.Blue,
                MarkerType = MarkerType.Circle,
                Title = "设计线"
            };

            dmxSseries = new LineSeries()
            {
                Color = OxyColors.Black,
                StrokeThickness = 1,
                //MarkerSize = 1,
                //MarkerStroke = OxyColors.Blue,
                //MarkerType = MarkerType.Circle,
                Title = "地面线"
            };

            this.DynamicCurve.Series.Add(sjxSseries);
            this.DynamicCurve.Series.Add(dmxSseries);

            //DispatcherTimer timer = new DispatcherTimer();
            //timer.Interval = TimeSpan.FromMilliseconds(10);
            //timer.Tick += (s, e) =>
            //{
            //    double cpuUsage = cpuCounter.NextValue();

            //    series.Points.Add(new DataPoint(index++, cpuUsage));
            //};
            //timer.Start();

            //DispatcherTimer timer2 = new DispatcherTimer();
            //timer2.Interval = TimeSpan.FromMilliseconds(100);
            //timer2.Tick += (s, e) =>
            //{
            //    DynamicCurve.InvalidatePlot(true);
            //};
            //timer2.Start();
        }

        public PlotModel DynamicCurve { get; private set; }

        private LineSeries sjxSseries;

        private LineSeries dmxSseries;

        private int index;
    }
}
